package user

import (
	"context"
	"fmt"
	pb "wire/api/user"
	"wire/internal/service"

	"github.com/spf13/pflag"
)

type UserCli struct {
	us   *service.UserService
	flag *flags
}

type flags struct {
	uid    uint64
	status uint8
}

func flagParse() *flags {
	// 定义命令行参数
	f := &flags{}
	pflag.Uint64VarP(&f.uid, "uid", "u", 0, "")
	pflag.Uint8VarP(&f.status, "status", "t", 0, "")
	// 解析命令行参数
	pflag.Parse()
	return f
}

func NewUserCli(us *service.UserService) *UserCli {
	return &UserCli{
		us:   us,
		flag: flagParse(),
	}
}

// Get go run . user_get --uid 10086
func (c *UserCli) Get() func() {
	return func() {
		req := &pb.GetRequest{
			Id: c.flag.uid,
		}
		ctx := context.Background()
		res, err := c.us.Get(ctx, req)

		fmt.Printf("err: %+v\n", err)
		fmt.Printf("res: %+v\n", res)
	}
}

// List go run . user_list -t 2
func (c *UserCli) List() func() {
	return func() {
		fmt.Printf("flags: %+v\n", c.flag)
	}
}
